<?php if (!defined('BASEPATH'))exit('No direct script access allowed');

class Card extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('plat_model');
        $this->load->model('credit_model');
    }

    function index() {
        $bank_type = $this->credit['bank_type'];
        $use_type = $this->credit['use_type'];
        $degree_type = $this->credit['degree_type'];
        $coin_type = $this->credit['coin_type'];
        $organ_type = $this->credit['organ_type'];
        $this->assign("bank_type", $bank_type);
        $this->assign("use_type", $use_type);
        $this->assign("degree_type", $degree_type);
        $this->assign("coin_type", $coin_type);
        $this->assign("organ_type", $organ_type);
        $this->display('card/index.html');
    }
    
    
    function mlist(){
        if($_POST){
            $type = trim($_POST['type']);
            $pageIndex = isset($_REQUEST['pageIndex']) ? trim($_REQUEST['pageIndex']) : 0;
            $type = explode(",", $type);
            $where = array();
            $type[0] ? $where['bank_type'] = $type[0] : "";
            $type[1] ? $where['use_type'] = $type[1] : "";
            $type[2] ? $where['degree_type'] = $type[2] : "";
            $type[3] ? $where['coin_type'] = $type[3] : "";
            $type[4] ? $where['organ_type'] = $type[4] : "";
            $where['tan_credit.is_hide'] = 1;
            $records_per_page = 5;
            $totalCount = $this->credit_model->get_credit_count($where);
            $list = $this->credit_model->get_credit_list($where,$pageIndex * $records_per_page,$records_per_page);
            foreach ($list as $key=>$val){
				$str = '<div class="location">
					<div class="card-list">
						<a href="javascript:void(0);" class="fl" onclick="showCreditInfo('.$val['id'].');">
							<img src="'.$val['logo'].'" />
						</a>
						<div class="con fr">
							<div class="title">
								<a href="javascript:void(0);" class="name fl" onclick="showCreditInfo('.$val['id'].');">'.$val['title'].'</a>
								<a href="javascript:void(0);" class="card-choice fr" onclick="showCreditInfo('.$val['id'].');">查看详情<b class="icon icon-read-more"></b></a>
								<div class="clear"></div>
								<span><b class="icon icon-review"></b>'.$val['reviews'].'</span>
							</div>
							<div class="card-txt mt10">
								<ul>
									<li><b class="icon icon-list"></b>'.$val['activity_one'].'</li>
									<li><b class="icon icon-list"></b>'.$val['activity_two'].'</li>
									<li><b class="icon icon-list"></b>'.$val['activity_three'].'</li>
								</ul>
								<ul>
									<li><span>银行名称：</span>'.$val['bank_title'].'</li>
									<li><span>取现额度：</span>'.$val['withdraw_amount'].'</li>
                                    <li><span>年费政策：</span>'.$val['year_fee'].'</li>
								</ul>
								<ul>
									<li><span>免息期：</span>'.$val['interest_des'].'</li>
									<li><span>该卡类型：</span>'.$val['use_title'].'</li>
									<li><span>币种类型：</span>'.$val['coin_title'].' </li>
								</ul>
								<a href="'.$val['link'].'" target="_blank" class="apply-button fr">立即申请 </a>		
								<div class="clear"></div>
							</div>
						</div>
						<div class="clear"></div>
					</div>
							
				</div>';
                $list[$key]['str'] = str_replace('"', "'", $str);
            }
            
            $result = array(
                "reqStatus" => true,
                "data" => array(
                    "totalCount" => $totalCount ? $totalCount : 0,
                    "pageIndex" => $pageIndex,
                    "list" => $list
                )
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }
    }
    
    function info(){
        if($_POST){
            $credit = $this->credit_model->get(array("id"=>$_POST['id']));
            if(!$credit){
                $mess['reqStatus'] = false;
                $mess['errorMsg'] = "数据请求失败";
                echo JSON($mess);
            }
            
            $msg_str = "<div class='popup-credit-sign popup-box' style='display: block;'>
			<div class='card-detail'>
				<div class='credit-detai'>
					<div class='cd-title'>
						信用卡详情页
						<a href='#' class='fr icon icon-close popup-close'></a>
					</div>
					<div class='cd-detail plr20'>
						<img src='".$credit['logo']."' />
						<div class='fl ml20' style='width:500px'>
							<div class='title'>
								<p class='name'>".$credit['title']."</p>
								<span><b class='icon icon-review'></b>".$credit['reviews']."</span>
								
							</div>
							<div class='card-txt mt10'>
								<ul>
									<li><b class='icon icon-list'></b>".$credit['activity_one']."</li>
									<li><b class='icon icon-list'></b>".$credit['activity_two']."</li>
									<li><b class='icon icon-list'></b>".$credit['activity_three']."</li>
								</ul>
								<!--弹窗--立即申请-->
								<div class='card-choice fr'>
									<a href='".$credit['link']."' target='_blank' class='apply-button'>立即申请 </a>
								</div>
							</div>
						</div>
						<div class='clear'></div>
					</div>
				</div>
				<!--选项卡切换 tab-->
				<div class='tab plr20'>
					<span class='fl popup-credit-line tab-title'>
						基本信息
					</span>
					<span class='fl'>
						相关费用
					</span>
					<span class='fl'>
						专享特权
					</span>
				</div>
				<div class='credit-con ptb10-lr20'>
					<div class='card-detail-list'>
						<!--选项卡内容1--基本信息-->
						<div class='credit-txt'>
							".$credit['baseinfo']."
						</div>
						<!--选项卡内容2--相关费用-->
						<div class='credit-txt' style='display: none;'>
							".$credit['about_fee']."
						</div>
						<!--选项卡内容3--专享特权-->
						<div class='credit-txt' style='display: none;'>
							".$credit['privilege']."
						</div>						
					</div>
					<div class='clear'></div>
				</div>
			</div>
		</div>
		<div class='popup popup-box' style='display: block;'></div>";
            $result = array(
                "reqStatus" => true,
                "data" => $msg_str
            );
            echo json_encode($result,JSON_HEX_TAG);die;
        }else{
            $mess['reqStatus'] = false;
            $mess['errorCode'] = 1005;
            $mess['errorMsg'] = "非法请求";
            echo JSON($mess);
        }
    }
}
